package com.paradox.aggregation.provider.test;

import java.util.*;

public class StringTest2 {

    public static void main(String[] args) throws InterruptedException {
        Solution solution=new Solution();
        solution.jump(new int[]{2,3,1,1,4});
        //System.out.println(board);
    }

    static class Solution {
        public int jump(int[] nums) {
            if(nums.length==1) return 0;

            int count=0;
            int nextIndex=0;
            int reach=0;
            for(int i=0;i<nums.length;){
                reach=i+nums[i];
                for(int j=i+1;j<=reach && j<nums.length;j++){
                    if(j+nums[j]>reach){
                        reach=j+nums[j];
                        nextIndex=j;
                    }
                }
                i=nextIndex;
                count++;
                if(nextIndex>=nums.length-1) break;
            }
            return count;
        }
    }
}
